﻿//using System;
//using System.Text;
//using System.Collections.Generic;
//using System.Linq;
//using Microsoft.VisualStudio.TestTools.UnitTesting;
//using KarReq.Domain.Abstract;
//using KarReq.Domain.Entities;
//using KarReq.WebUI.Controllers;
//using Moq;
//using System.Web;
//using System.Web.Mvc;
//using KarReq.WebUI.Models;
//using KarReq.WebUI.HtmlHelpers;

//namespace KarReq.UnitTests
//{
//    [TestClass]
//    public class UnitTest1
//    {
//        [TestMethod]
//        public void Can_Generate_Page_Links()
//        {
//            // Arrange - define an HTML helper - we need to do this
//            // in order to apply the extension method
//            HtmlHelper myHelper = null;

//            // Arrange - create PagingInfo data
//            PagingInfo pagingInfo = new PagingInfo
//            {
//                CurrentPage = 2,
//                TotalItems = 28,
//                ItemsPerPage = 10
//            };

//            // Arrange - set up the delegate using a lambda expression
//            Func<int, string> pageUrlDelegate = i => "Page" + i;

//            // Act
//            MvcHtmlString result = myHelper.PageLinks(pagingInfo, pageUrlDelegate);

//            // Assert
//            Assert.AreEqual(result.ToString(), @"<a href=""Page1"">1</a><a class=""selected"" href=""Page2"">2</a><a href=""Page3"">3</a>");
//        }

//        [TestMethod]
//        public void Can_Send_Pagination_View_Model()
//        {
//            // Arrange
//            // - create the mock repository
//            Mock<IKaraokeTrackRepository> mock = new Mock<IKaraokeTrackRepository>();
//            mock.Setup(m => m.KaraokeTracks).Returns(new KaraokeTrack[] {
//                new KaraokeTrack {KaraokeTrackID = 1, Artist = "P1"},
//                new KaraokeTrack {KaraokeTrackID = 2, Artist = "P2"},
//                new KaraokeTrack {KaraokeTrackID = 3, Artist = "P3"},
//                new KaraokeTrack {KaraokeTrackID = 4, Artist = "P4"},
//                new KaraokeTrack {KaraokeTrackID = 5, Artist = "P5"}
//            }.AsQueryable());
//            // Arrange - create a controller and make the page size 3 items
//            KaraokeTrackController controller = new KaraokeTrackController(mock.Object);
//            controller.PageSize = 3;
//            // Action
//            KaraokeTracksListViewModel result = (KaraokeTracksListViewModel)controller.List(null, 2).Model;
//            // Assert
//            PagingInfo pageInfo = result.PagingInfo;
//            Assert.AreEqual(pageInfo.CurrentPage, 2);
//            Assert.AreEqual(pageInfo.ItemsPerPage, 3);
//            Assert.AreEqual(pageInfo.TotalItems, 5);
//            Assert.AreEqual(pageInfo.TotalPages, 2);
//        }

//        [TestMethod]
//        public void Can_Paginate()
//        {
//            // Arrange
//            // - create the mock repository
//            Mock<IKaraokeTrackRepository> mock = new Mock<IKaraokeTrackRepository>();
//            mock.Setup(m => m.KaraokeTracks).Returns(new KaraokeTrack[] {
//                new KaraokeTrack {KaraokeTrackID = 1, Artist = "P1"},
//                new KaraokeTrack {KaraokeTrackID = 2, Artist = "P2"},
//                new KaraokeTrack {KaraokeTrackID = 3, Artist = "P3"},
//                new KaraokeTrack {KaraokeTrackID = 4, Artist = "P4"},
//                new KaraokeTrack {KaraokeTrackID = 5, Artist = "P5"}
//            }.AsQueryable());
//            // create a controller and make the page size 3 items
//            KaraokeTrackController controller = new KaraokeTrackController(mock.Object);
//            controller.PageSize = 3;
//            // Action
//            KaraokeTracksListViewModel result = (KaraokeTracksListViewModel)controller.List(null, 2).Model;
//            // Assert
//            KaraokeTrack[] prodArray = result.KaraokeTracks.ToArray();
//            Assert.IsTrue(prodArray.Length == 2);
//            Assert.AreEqual(prodArray[0].Artist, "P4");
//            Assert.AreEqual(prodArray[1].Artist, "P5");
//        }

//        [TestMethod]
//        public void Can_Add_New_Lines()
//        {
//            // Arrange - create some test products
//            KaraokeTrack p1 = new KaraokeTrack { KaraokeTrackID = 1, Artist = "P1" };
//            KaraokeTrack p2 = new KaraokeTrack { KaraokeTrackID = 2, Artist = "P2" };
//            // Arrange - create a new cart
//            Queue target = new Queue();
//            // Act
//            target.AddItem(p1);
//            target.AddItem(p2);
//            QueueLine[] results = target.Lines.ToArray();
//            // Assert
//            Assert.AreEqual(results.Length, 2);
//            Assert.AreEqual(results[0].KaraokeTrack, p1);
//            Assert.AreEqual(results[1].KaraokeTrack, p2);
//        }

//        [TestMethod]
//        public void Can_Remove_Line()
//        {
//            // Arrange - create some test products
//            KaraokeTrack p1 = new KaraokeTrack { KaraokeTrackID = 1, Artist = "P1" };
//            KaraokeTrack p2 = new KaraokeTrack { KaraokeTrackID = 2, Artist = "P2" };
//            KaraokeTrack p3 = new KaraokeTrack { KaraokeTrackID = 3, Artist = "P3" };
//            // Arrange - create a new cart
//            Queue target = new Queue();
//            // Arrange - add some products to the cart
//            target.AddItem(p1);
//            target.AddItem(p2);
//            target.AddItem(p3);
//            // Act
//            target.RemoveLine(p2);
//            // Assert
//            Assert.AreEqual(target.Lines.Where(c => c.KaraokeTrack == p2).Count(), 0);
//            Assert.AreEqual(target.Lines.Count(), 2);
//        }

//        [TestMethod]
//        public void Can_Clear_Contents()
//        {
//            // Arrange - create some test products
//            KaraokeTrack p1 = new KaraokeTrack { KaraokeTrackID = 1, Artist = "P1", Song = "A1" };
//            KaraokeTrack p2 = new KaraokeTrack { KaraokeTrackID = 2, Artist = "P2", Song = "A2" };
//            // Arrange - create a new cart
//            Queue target = new Queue();
//            // Arrange - add some items
//            target.AddItem(p1);
//            target.AddItem(p2);
//            // Act - reset the cart
//            target.Clear();
//            // Assert
//            Assert.AreEqual(target.Lines.Count(), 0);
//        }

//        [TestMethod]
//        public void Can_Add_To_Queue()
//        {
//            // Arrange - create the mock repository
//            Mock<IKaraokeTrackRepository> mock = new Mock<IKaraokeTrackRepository>();
//            mock.Setup(m => m.KaraokeTracks).Returns(new KaraokeTrack[] {
//                new KaraokeTrack {KaraokeTrackID = 1, Artist = "P1", Song = "Apples"},
//            }.AsQueryable());
//            // Arrange - create a Queue
//            Queue queue = new Queue();
//            // Arrange - create the controller
//            QueueController target = new QueueController(mock.Object);
//            // Act - add a product to the cart
//            target.AddToQueue(queue, 1, null);
//            // Assert
//            Assert.AreEqual(queue.Lines.Count(), 1);
//            Assert.AreEqual(queue.Lines.ToArray()[0].KaraokeTrack.KaraokeTrackID, 1);
//        }

//        [TestMethod]
//        public void Adding_Product_To_Queue_Goes_To_Cart_Screen()
//        {
//            // Arrange - create the mock repository
//            Mock<IKaraokeTrackRepository> mock = new Mock<IKaraokeTrackRepository>();
//            mock.Setup(m => m.KaraokeTracks).Returns(new KaraokeTrack[] {
//                new KaraokeTrack {KaraokeTrackID = 1, Artist = "P1", Song = "Apples"},
//            }.AsQueryable());
//            // Arrange - create a Queue
//            Queue queue = new Queue();
//            // Arrange - create the controller
//            QueueController target = new QueueController(mock.Object);
//            // Act - add a product to the cart
//            RedirectToRouteResult result = target.AddToQueue(queue, 2, "myUrl");
//            // Assert
//            Assert.AreEqual(result.RouteValues["action"], "Index");
//            Assert.AreEqual(result.RouteValues["returnUrl"], "myUrl");
//        }

//        [TestMethod]
//        public void Can_View_Queue_Contents()
//        {
//            // Arrange - create a Cart
//            Queue queue = new Queue();
//            // Arrange - create the controller
//            QueueController target = new QueueController(null);
//            // Act - call the Index action method
//            QueueIndexViewModel result
//                = (QueueIndexViewModel)target.Index(queue, "myUrl").ViewData.Model;
//            // Assert
//            Assert.AreSame(result.Queue, queue);
//            Assert.AreEqual(result.ReturnUrl, "myUrl");
//        }

//    }
//}
